package com.tinycloud.miracll.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tinycloud.common.log.annotation.Log;
import com.tinycloud.common.log.enums.BusinessType;
import com.tinycloud.common.security.annotation.PreAuthorize;
import com.tinycloud.miracll.product.domain.ProductPoint;
import com.tinycloud.miracll.product.service.IProductPointService;
import com.tinycloud.common.core.web.controller.BaseController;
import com.tinycloud.common.core.web.domain.AjaxResult;
import com.tinycloud.common.core.utils.poi.ExcelUtil;
import com.tinycloud.common.core.web.page.TableDataInfo;

/**
 * 点位管理Controller
 * 
 * @author tiny
 * @date 2021-08-25
 */
@RestController
@RequestMapping("/productPoint")
public class ProductPointController extends BaseController
{
    @Autowired
    private IProductPointService productPointService;

    /**
     * 查询点位管理列表
     */
    @PreAuthorize(hasPermi = "product:productPoint:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductPoint productPoint)
    {
        startPage();
        List<ProductPoint> list = productPointService.selectProductPointList(productPoint);
        return getDataTable(list);
    }

    /**
     * 导出点位管理列表
     */
    @PreAuthorize(hasPermi = "product:productPoint:export")
    @Log(title = "点位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductPoint productPoint) throws IOException
    {
        List<ProductPoint> list = productPointService.selectProductPointList(productPoint);
        ExcelUtil<ProductPoint> util = new ExcelUtil<ProductPoint>(ProductPoint.class);
        util.exportExcel(response, list, "点位管理数据");
    }

    /**
     * 获取点位管理详细信息
     */
    @PreAuthorize(hasPermi = "product:productPoint:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(productPointService.selectProductPointById(id));
    }

    /**
     * 新增点位管理
     */
    @PreAuthorize(hasPermi = "product:productPoint:add")
    @Log(title = "点位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPoint productPoint)
    {
        return toAjax(productPointService.insertProductPoint(productPoint));
    }

    /**
     * 修改点位管理
     */
    @PreAuthorize(hasPermi = "product:productPoint:edit")
    @Log(title = "点位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPoint productPoint)
    {
        return toAjax(productPointService.updateProductPoint(productPoint));
    }

    /**
     * 删除点位管理
     */
    @PreAuthorize(hasPermi = "product:productPoint:remove")
    @Log(title = "点位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productPointService.deleteProductPointByIds(ids));
    }
}
